const aaa = new Vue({
    el:"#app",
    data:{
        message:"hello,guys",
        list: [
            {
                id: 1,
                name: '《算法导论》',
                date: '2006-9',
                price: 85.00,
                count: 1
            },
            {
                id: 2,
                name: '《UNIX编程艺术》',
                date: '2006-2',
                price: 59.00,
                count: 1
            },
            {
                id: 3,
                name: '《编程珠玑》',
                date: '2008-10',
                price: 39.00,
                count: 1
            },
            {
                id: 4,
                name: '《代码大全》',
                date: '2006-3',
                price: 128.00,
                count: 1
            },
        ]
    },
    filters:{
        showPrice(price){
            return "¥" + price.toFixed(2);
        }
    },
    methods:{
        inc(index){
            this.list[index].count++;
        },
        dec(index){
            this.list[index].count--;
        },
        removeBook(index){
            this.list.splice(index, 1);
        }
    },
    computed:{
        totalPrice(){
            let totalPrice = 0;
            for(let i of this.list){
                totalPrice += i.price * i.count;
            }
            return totalPrice;
        }
    }
})

//将下列数组中小于5的数组*10再求和
const nums = [1, 2, 3, 4, 5, 6, 7];
//method1:
//filter函数：通过自己设立条件过滤数字
let nums1 = nums.filter(function (n) {
    if(n < 5) return true;
});
console.log("nums1:" + nums1);
//map函数： 让数组中所有元素都执行某操作
let nums2 = nums1.map(function (n) {
    return n * 2;
});
console.log("nums2:" + nums2);
//reduce函数： 汇总数组中内容
let nums3 = nums2.reduce(function (preNum, n) {
    return n + preNum;
}, 0);
console.log("nums3:" + nums3);

//method2:
let nums4 = nums.filter(function (n) {
    if(n < 5) return true;
}).map(function (n) {
    return n * 2;
}).reduce(function (preNum, n) {
    return preNum + n;
});
console.log("nums4:" + nums4);
console.log("nums:" + nums);